package com.googlecode.stemwijzer.server.rest;

import java.io.IOException;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.annotation.security.RolesAllowed;
import javax.ws.rs.Path;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.googlecode.stemwijzer.client.StemwijzerService;
import com.googlecode.stemwijzer.server.security.Roles;
import com.sun.jersey.api.json.JSONWithPadding;

/**
 * The class SecureStemwijzerRestServlet.
 * 
 * @author j.brosens (RemoteServlet, Method implementation), roel.hodzelmans (Rest annotations).
 */
@Singleton
@Resource
@Path("/secured")
public class SecureStemwijzerRestServlet extends StemwijzerRestServlet {

	@Inject
	public SecureStemwijzerRestServlet(final StemwijzerService service, final ObjectMapper mapper) {
		super(service, mapper);

		this.service = service;
		this.mapper = mapper;
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see com.googlecode.stemwijzer.server.rest.StemwijzerRestServlet#getResult(java.lang.String)
	 */
	@Override
	@RolesAllowed( { Roles.USER })
	public JSONWithPadding getResult(final String callback) throws JsonGenerationException, JsonMappingException,
			IOException {
		return super.getResult(callback);
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see com.googlecode.stemwijzer.server.rest.StemwijzerRestServlet#registerUser(java.lang.String, java.lang.String)
	 */
	@Override
	@PermitAll
	public JSONWithPadding registerUser(final String userName, final String callback) throws JsonGenerationException,
			JsonMappingException, IOException {
		return super.registerUser(userName, callback);
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see com.googlecode.stemwijzer.server.rest.StemwijzerRestServlet#resetSession(java.lang.String)
	 */
	@Override
	@RolesAllowed( { Roles.USER })
	public JSONWithPadding resetSession(final String callback) throws JsonGenerationException, JsonMappingException,
			IOException {
		return super.resetSession(callback);
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see com.googlecode.stemwijzer.server.rest.StemwijzerRestServlet#sendAnswer(com.googlecode.stemwijzer.shared.model.impl.Question,
	 *      com.googlecode.stemwijzer.shared.model.impl.Answer, java.lang.String)
	 */
	@Override
	@RolesAllowed( { Roles.USER })
	public JSONWithPadding sendAnswer(final String question, final String answer, final String callback)
			throws JsonGenerationException, JsonMappingException, IOException {
		return super.sendAnswer(question, answer, callback);
	}
}
